//
//  LinkBL.m
//  IPCamera
//
//  Created by 宣佚 on 15/5/29.
//  Copyright (c) 2015年 Andon Health Co,.Ltd. All rights reserved.
//

#import "LinkBL.h"


@implementation LinkBL

+(instancetype)sharedHandler
{
        //使用iOS的单例创造方式
    static LinkBL *_sharedHandler = nil;
        //确保代码块只被调用一次的变量
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        _sharedHandler = [[LinkBL alloc] init];
    });
        //返回一个单例
    return _sharedHandler;
}

- (NSString *)CheckLinkInfoTip_LinkType:(ENUM_LINKTYPE)LinkType
                               deviceID:(NSString *)deviceID
                               username:(NSString *)username
                               password:(NSString *)password
{
    if (!LinkType || LinkType == 0) {
        return @"请填选择连接类型";
    }
    if (!deviceID || deviceID.length <= 0) {
        return @"请填写设备ID";
    }
    if (!username || username.length <= 0) {
        return @"请填写用户名";
    }
    if (!password || password.length <= 0) {
        return @"请填写密码";
    }
    return nil;
}

-(BOOL)writeDeviceIDToDeivesList:(NSString *)DeviceID linkType:(ENUM_LINKTYPE)linkType
{
    if (linkType == 0) {
        return NO;
    }
    else {
        NSMutableArray *data = [[PlistFileManage sharedHandler] readDeviceList:linkType];
        BOOL ret = [data containsObject:DeviceID];
        if (ret == NO) {
            [data addObject:DeviceID];
            return [[PlistFileManage sharedHandler] refreshDeviceList:data linkType:linkType];
        }
        else {
            return YES;
        }
    }
}

@end
